package CalendarComponents;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import Managers.Appointment;
import Managers.Category;

//this class if for defining how a cell in a combo box, JList or anything similar should draw it's inner components.
class FullRend extends Rend
{
	  private DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();

	  @Override
	  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
	  {
		 //get appointment
		Appointment a = ((Appointment)value); 
		
		//get the category
		Category c = a.getCategory();
	
		//get the color
        Color color = c.getColor();

        //create a new icon
        ColorIcon icon = new ColorIcon(10,10,color);
 
        //get the renderer
	    JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
	    //renderer.setPreferredSize(new Dimension(800,30));
	    renderer.setIcon(icon); //set the icon
	    if(a.getDescription().length() == 0)
	    {
	    	renderer.setText(String.format("%s", a.toString()));//set the text
	    }
	    else
	    {
	    	renderer.setText(String.format("%s - %s", a.toString(),a.getDescription()));//set the text
	    }
	    //renderer.setFont(new Font("Ariel", Font.BOLD, 15));
	    return renderer;//return
	  }
}